<include file="../Public/header" />

    <link href="__PUBLIC__/themes/blue/layout.css" rel="stylesheet" type="text/css" />
    

<script type="text/javascript" src="__PUBLIC__/js/tbox/tbox.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/admin.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-admin-box.js"></script>

<script>
	// tbox用常量
	var THEME = "__THEME__";
	var APP    = "__APP__";
	var URL    = "__URL__";
	var PUBLIC = "../Public";
	var SITE_URL = "{*SITE_URL}";
	
//全选,全不选，反选
var idField = 'checkboxIds';
function checkall(type){
	 //全选
	if(type=='all'){ 
	    $("input[id='"+idField+"']").each(function() {     
	       $(this).attr("checked", true);    
	    });	
	//全不选
	}else if(type=='noall'){  
		$("input[id='"+idField+"']").each(function() {     
				$(this).attr("checked", false);    
		});		
	//反选
	}else {
		$("input[id='"+idField+"']").each(function() {     
				var aa = $(this).attr("checked");
				
				if(aa==false) $(this).attr("checked", true); 
				else          $(this).attr("checked", false);    
		});		
	}
}	

function getSelectValues() {
	id = [];	
	$("input[id='"+idField+"']").each(function() {     
			var aa = $(this).attr("checked");
			
			if(aa==true) {id.push( $(this).val() ); }
	});		
	return id.join(',');
}

function outExcel(){
	var id = getSelectValues();
	if(id==''||id=='undefined'){
		alert('请选择需要导出的投票');
		return false;
	}
	
	var url = "{:U('home/Vote/outExcel')}&id="+id;
	
	window.location.href = url;
}
</script>

<body>
<div id="container_s">
	<!-- 搜索位 BEGIN -->
	<form  action="{:U('admin/System/vote')}" method="POST">
		<table class="tableborder" width="100%" id="search">
		  <tbody>
			<tr class="top">
			  <td class="border" colspan="2">
			  </td>
			</tr>
			<tr onClick="$('#search .cell').toggle();">
			  <th class="header" colspan="2">筛选条件</th>
			</tr>
			<tr class="label cell">
			  <th>说明</th>
			  <th>条件</th>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>投票ID</b><br/>
				<span class="smalltxt">搜索指定的投票</span>
			  </td>
			  <td class="altbg2">
				<input name="id" class="txt" value="{$id}"/> [ 注：多个投票时请以英文的“,”分割 ]
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>用户ID</b><br/>
				<span class="smalltxt">搜索该用户发起的附件</span>
			  </td>
			  <td class="altbg2">
				<input name="userId" class="txt" value="{$userId}"/> [ 注：多用户时请以英文的“,”分割 ]
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>投票标题</b><br/>				
				<span class="smalltxt">根据投票标题搜索,支持模糊查询</span>
			  </td>
			  <td class="altbg2"><input name="key" class="txt" value="{$key}"/> [ 注：使用“%”作为通配符 ]</td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>投票类型</b><br/>
				<span class="smalltxt">只看给定类型的投票</span>
			  </td>
			  <td class="altbg2">
				<select name="vote_type">
					<option value="2" <eq name="vote_type" value="2">selected</eq>>所有</option>
					<option value="0" <eq name="vote_type" value="0">selected</eq>>单选</option>
					<option value="1" <eq name="vote_type" value="1">selected</eq>>多选</option>
				</select>
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>应用类型</b><br/>
				<span class="smalltxt">只看给定应用的投票</span>
			  </td>
			  <td class="altbg2">
				<select name="app">
					<option value="0" <eq name="app" value="0">selected</eq>>所有</option>
					<option value="1" <eq name="app" value="1">selected</eq>>BBS</option>
					<option value="2" <eq name="app" value="2">selected</eq>>团队BBS</option>
				</select>
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>是否匿名</b><br/>
				<span class="smalltxt">只看给定匿名条件的投票</span>
			  </td>
			  <td class="altbg2">
				<select name="is_anonymous">
					<option value="2" <eq name="is_anonymous" value="2">selected</eq>>所有</option>
					<option value="0" <eq name="is_anonymous" value="0">selected</eq>>不匿名</option>
					<option value="1" <eq name="is_anonymous" value="1">selected</eq>>匿名</option>
				</select>
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>结果排序</b><br/>
			  </td>
			  <td class="altbg2">
				<select name="field">
				  <option value="cTime" <eq name="field" value="cTime">selected</eq>>按发起时间排序</option>
				  <option value="vote_num" <eq name="field" value="vote_num">selected</eq>>按投票数排序</option>
				</select>

				<select name="order">
				  <option value="DESC" <eq name="order" value="DESC">selected</eq>>降序</option>
				  <option value="ASC" <eq name="order" value="ASC">selected</eq>>升序</option>
				</select>
	   
				<select name="limit">
				  <option value="20" <eq name="limit" value="20">selected</eq>>每页显示20条</option>
				  <option value="50" <eq name="limit" value="50">selected</eq>>每页显示50条</option>
				  <option value="100" <eq name="limit" value="100">selected</eq>>每页显示100条</option>
				</select>
			  </td>
			</tr>

			<tr class="cell">
				<td>&nbsp;</td>
				<td class="pt10 pb10"><input type="submit" class="button" value="提交" /></td>
			</tr>
		  </tbody>
		</table>
	</form>
	<!-- 搜索位 END -->
	
	<!-- 正文 BEGIN -->
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder" id="checkList">
		<tbody>
			<!-- 列表标题 -->
			<tr class="top">
				<td class="border" colspan="7"></td>
			</tr>
			<tr>
				<th class="header" colspan="7"> 投票列表 </th>
			</tr>

			<!-- 列表字段 -->
			<tr class="label cell">
				<th>&nbsp;</th>
				<th>ID</th>
				<th>名称</th>
				<th>类型</th>
				<th>应用类型</th>
				<th>发起人</th>
				<th>查看详情</th>
			</tr>
			
			<!-- 列表数据 -->
			<volist name="data" id='vo'>
			<tr id="list_{$vo.id}" class="cell">
				<td><label><input type="checkbox" class="vote_admin_check" rel="0" value="{$vo['id']}"  dataid="{$vo['id']}" id="checkboxIds"></label></td>
				<td>{$vo.id}</td>
				<td><a href="javascript:void(0)" onClick="show_vote({$vo.id});">{$vo.title}</a></td>
				<td><eq name="vo['type']" value="0">单选<else/>多选</eq></td>
				<td>
					<php>
					if($vo['app'] == 'bbs' && $vo['groupId'] == 0) {
						echo 'BBS';
					}else if($vo['app'] == 'bbs' && $vo['groupId'] != 0) {
						echo '团队BBS';
					}
					</php>
				</td>
				<td><a href="{:U('space/View/index',array('uid'=>$vo['uid']))}" target="_blank">{$vo.uid|getUserName}</a></td>
				<td>
				    <neq name="vo.groupId" value="0">
				    <a href="{:U('group/Forum/detail',array('gid'=>$groupId,'tid'=>$vo['fieldId']))}" target="_blank">
				        <else/>
				        <a href="{:U('bbs/Index/detail',array('id'=>$vo['fieldId']))}" target="_blank">
				        </neq>
				        查看详情</a>
				    
				    &nbsp;&nbsp;<a href="{:U('home/Vote/outExcel',array('id'=>$vo['id']))}">导出Excel</a>
				    </td>
			</tr>
			</volist>

			<tr>
				<td class="footer" colspan="7">
                        <button type="button" onClick="checkall('all')" class="btn_sea">全选</button>
                        <button type="button" onClick="checkall('noall')"  class="btn_sea">全不选</button>
                        <button type="button" onClick="checkall('')" class="btn_sea">反选</button>
                        <button type="button" onClick="outExcel()" class="btn_sea">导出Excel</button>
				</td>
			</tr>

			<tr>
				<td class="footer" colspan="7">
					<div class="page mt5 alR mb20" style="float:right;">{$html}</div>
				</td>
			</tr>

			<tr class="bottom">
				<td class="border" colspan="7"></td>
			</tr>

		</tbody>
	</table>
	<!-- 正文 END -->
</div>

<!-- 前台管理 BEGIN -->
<div id="vote_admin" style="display:none;">
	<a href="javascript:void(0)" onClick="deleteVote()">删除投票</a>
</div>
<!-- 前台管理 END -->

<!-- 页面JS BEGIN -->
<script type="text/javascript">
	//加载前台管理工具
	$(function(){
		$.fn.admin({
			prefix:'vote_',
			checkClass:'vote_admin_check',
			hiddenId:'vote_admin',
			lMinOffset:1,
			type:false,
			position:'right'
		});
	});

	//删除附件至回收站
	function deleteVote() {
		if(confirm('删除投票将导致投票贴失效，且无法恢复！确认删除？')){
			$.post("{:U('admin/System/doDeleteVote')}", {id:$.fn.getData('vote_')}, function(result){
				if(result == 1) {
					$.tbox.yes('删除成功',"提示");
					setTimeout("$.tbox.close()",1500);
					$.each($.fn.getData('vote_'),function(i,n){
						$("#list_"+n).remove();
					});
					$('#vote_admin_box').hide();
				}else{
					$.tbox.no('删除失败',"提示");
					setTimeout("$.tbox.close()",1500);
				}
			});
		}
	}

	//查看投票详情
	function show_vote(vid) {
		$.tbox.popup("{:U('home/Vote/showVote')}&id="+vid,"投票详情",true);
	}
</script>
<!-- 页面JS END -->

</body>
</html>